﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInputControl.h"
namespace gnuf {
    class Info;
    class Item;

    class GNUF_BASE_EXPORT IDropdownMenuControlHandler
        : public IInputControlHandler
    {
    public:
        virtual void onCurrentIndexChanged(int, Item*) {}
        virtual void onCheckStatusChanged(int, bool) {}
        virtual void onCheckStatusChanged(const std::vector<bool>&) {}
    };

    class GNUF_BASE_EXPORT DropdownMenuControlAdpatation
        : public InputControlAdaptation
    {
    public:
        enum MenuItemType {
            ePushButton,
            eCheckButton,
            eRadioButton,
            eInlineMenu,
            eOutlineMenu
        };

    protected:
        DropdownMenuControlAdpatation();
        virtual ~DropdownMenuControlAdpatation();

        //
        // Inherits from InputControlAdaptation...
        virtual void onVisibilityChanged(bool) override {}
        virtual void onAbilityChanged(bool) override {}
        virtual void onSelectionChanged(bool) override {}

    public:
        virtual void onItemsVisibilityAndAbilityChanged(const std::vector<bool> &, const std::vector<bool> &) {}
        virtual void onCurrentIndexChanged(int) {}
        virtual void onCheckStatusChanged(int, bool) {}
        virtual void onCheckStatusChanged(const std::vector<bool>&) {}

    public:
        virtual void setCaption(const std::wstring& caption) {}
        virtual void insertMenuItem(int, const Info&, MenuItemType) {}
        virtual void addMenuItem(const Info&, MenuItemType) {}
        virtual void addMenuGroup() {}
        virtual void removeMenuItem(int) {}
        virtual void renameMenuItemInfo(int, const Info&) {}
        virtual void renameMenuItem(int, const std::wstring&) {}
        virtual void selectMenuItem(int) {}
        virtual void setCustomizeArrowPathforIndexOfButton(int,const Info&) {}
        virtual void removeSeparator(int) {}
        virtual void menuItemCount(int& index) const {}

        virtual Item* menuItem(int idx) { return nullptr; }
    };

    class GNUF_BASE_EXPORT DropdownMenuControl final
        : public InputControl
    {
        typedef DropdownMenuControlAdpatation::MenuItemType MenuItemType;
        CANNOT_COPY_OR_ASSIGN(DropdownMenuControl)
    public:
        static const EItemType Type;
        DropdownMenuControl(IDropdownMenuControlHandler *, gcmp::OwnerPtr< Info > &);
        virtual ~DropdownMenuControl();

        const Info * info() const { return m_info.get(); }

        void setCurrentIndex(int, DropdownMenuControlAdpatation * trigger = nullptr);
        void setCheckStatus(int, bool, const DropdownMenuControlAdpatation * trigger = nullptr);
        void setCheckStatus(const std::vector<bool>&, const DropdownMenuControlAdpatation* trigger = nullptr);

        void setItemsVisibleAndEnabled(const std::vector<bool> &, const std::vector<bool> &);

        void setCaption(const std::wstring& caption, const DropdownMenuControlAdpatation * trigger = nullptr);

        void insertMenuItem(int, const Info&, MenuItemType, const DropdownMenuControlAdpatation * trigger = nullptr);

        void addMenuItem(const Info&, MenuItemType, const DropdownMenuControlAdpatation * trigger = nullptr);
        
        void addMenuGroup(const DropdownMenuControlAdpatation * trigger = nullptr);

        void removeMenuItem(int, const DropdownMenuControlAdpatation * trigger = nullptr);

        void renameMenuItemInfo(int, const Info&, const DropdownMenuControlAdpatation * trigger = nullptr);

        void renameMenuItem(int, const std::wstring&, const DropdownMenuControlAdpatation * trigger = nullptr);

        void selectMenuItem(int, const DropdownMenuControlAdpatation * trigger = nullptr);
        void setCustomizeArrowPathforIndexOfButton(int, const Info&, const DropdownMenuControlAdpatation * trigger = nullptr);
        void removeSeparator(int, const DropdownMenuControlAdpatation* trigger = nullptr);

        void menuItemCount(int& index) const;
    private:
        gcmp::OwnerPtr< Info > m_info;
    };
}
